using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NoteTrigger : MonoBehaviour
{
    public bool canBePoress;  
    public KeyCode keyForPress;
    public GameManager GameManager;
    public float preferAdjust;
    void Start()
    {
        
    }

    void Update()
    {
        if (Input.GetKeyDown(keyForPress))
        {
            if (canBePoress)
            {
                gameObject.SetActive(false);

                if(transform.position.y <= -3.2f + preferAdjust && transform.position.y >= -3.2f - preferAdjust)
                {
                    //Debug.Log("300");
                    GameManager.instance.PreferHit();
                }
                else
                {
                    GameManager.instance.NormalHit();
                    //Debug.Log("100");
                }
            }
        }
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Activator")
        {
            canBePoress = true;
        }
            
    }
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.tag == "Activator" && gameObject.activeSelf)
        {
            canBePoress = false;
            GameManager.instance.NoteMiss();
        }
    }
}
